﻿@inject ISettingService _settingService

@if (Model.Any())
{
    <MRow>

        @foreach (var item in _items)
        {
            <MCol Cols="@(_settingService.IsApp?6:4)">
                @foreach (var info in item)
                {
                    <div class="mb-4">
                        <CnGalWebSite.ProjectSite.Shared.Components.Shared.InfoCards.StallInfoCard Model="info" />
                    </div>
                }
            </MCol>
        }

    </MRow>
}
else
{
    <NotFoundCard Fill />
}


@code {
    [Parameter]
    public List<StallInfoViewModel> Model { get; set; }

    List<List<StallInfoViewModel>> _items = new List<List<StallInfoViewModel>>();

    protected override void OnInitialized()
    {
        var count = (_settingService.IsApp ? 2 : 3);
        _items.Clear();
        for (var i = 0; i < count; i++)
        {
            _items.Add(new List<StallInfoViewModel>());
        }
        var index = 0;
        foreach (var item in Model)
        {
            _items[index].Add(item);
            index++;
            if (index == count)
            {
                index = 0;
            }
        }
    }

}
